package com.course.controller;

import com.course.config.CodeGenerator;
import com.course.entity.ResultBody;
import com.course.service.SubjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/Subject")
@CrossOrigin(origins="*")
//课程管理
public class SubjectConroller {
    @Autowired
    private SubjectService subjectService;
    //增加课程
    @RequestMapping("/addsubject")
    public ResultBody addsubject(@RequestBody Map<String,Object> map){
       if(map.get("subjectnumber")==null||map.get("subjectplace")==null||map.get("subjecttime")==null||map.get("subjectname")==null||map.get("subjectcollege")==null||map.get("subjectclass")==null||map.get("subjectteacher")==null||map.get("subjectday")==null||map.get("subjectpoint")==null||map.get("subjectid")==null)
       {
           return new ResultBody(404,"参数错误",false);
       }

        return subjectService.addsubject(map);
    }
    //删除课程
    @RequestMapping("/deletesubject")
    public ResultBody deletesubject(@RequestBody Map<String,Object> map){
        if(map.get("id")==null){
            return new ResultBody(404,"参数错误",false);
        }
        return subjectService.delsubject(map);
    }
    //修改课程
    @RequestMapping("/updatesubject")
    public ResultBody updatesubject(@RequestBody Map<String,Object> map){
        if(map.get("subjectnumber")==null&&map.get("subjectplace")==null&&map.get("subjecttime")==null&&map.get("subjectname")==null&&map.get("subjectcollege")==null&&map.get("subjectclass")==null&&map.get("subjectteacher")==null&&map.get("subjectday")==null&&map.get("subjectpoint")==null){
            return new ResultBody(404,"参数错误",false);
        }
        return subjectService.updatesubject(map);
    }
    //展示课程
    @RequestMapping("/displaysubject")
    public ResultBody displaysubject(){
        return subjectService.displaysubject();
    }
}
